// thunk: 处理异步action
function thunk(store) {
  // 1. 获取dispatch
  const next = store.dispatch;
  // 2. 重写dispatch
  function dispatchThunk(action) {
    // 3. 判断action是否为函数
    if (typeof action === 'function') {
      // 4. 执行函数
      return action(store.dispatch, store.getState);
    } else {
      // 5. 不是函数，调用next
      return next(action);
    }
  }
  // 6. 修改store.dispatch
  store.dispatch = dispatchThunk;
}

export default thunk;